﻿/**
 * 派生自DynamicObject类对象
 * author: zjh
 * create: 2019/08/02 15:48
 * 
 * */
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicObjectClass
{
    /// <summary>
    /// DynamicObject派生类
    /// </summary>
    public class Teacher : DynamicObject
    {
        private Dictionary<string, object> members = new Dictionary<string, object>();

        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            var name = binder.Name;
            Console.WriteLine("set member: {0}={1}", name, value.ToString());
            members[name] = value;
            return true;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var name = binder.Name;
            Console.WriteLine("get member: {0}", name);
            return members.TryGetValue(name, out result);
        }
    }
}
